<?php
declare (strict_types = 1);
namespace app\course\logic\video\admin;

use app\course\model\base\CourseSection;
use app\course\model\video\admin\Order as OrderModel;

/**
 * 订单管理逻辑层
 */
class Order extends OrderModel
{
    /**
     * 获取订单列表
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-04
     * @param    array                          $map [description]
     * @return   [type]                              [description]
     */
    public function getList(array $map)
    {
        return $this->with(['course', 'transaction', 'school', 'user', 'pdorder'])->withJoin(['user', 'pdorder','transaction'], 'LEFT')
            ->where($map)->order('update_time', 'DESC')->paginate($this->getListRows())->each(function ($item) {
            $title = $item->product_title;
            if ($item->section_id) {
                // 查询课时名称
                $title .= ' - ' . CourseSection::withTrashed()->where('id', $item->section_id)->value('title');
                $title = '购买课时【' . $title . '】';
            } else {
                $title = $title ? '购买课程【' . $title . '】' : '购买课程';
            }

            $item->product_title = $title;
        });
    }
}
